/**
 * Created by LUOLIANG on 2016/6/10.
 */
var logincontroller = avalon.define({
    $id: "logincontroller",
    username: "",
    password: "",
    cusername: "",
    cnickname: "",
    password1: "",
    password2: "",

    login: function () {
        if (logincontroller.username == "" || logincontroller.password == "") {
            toastr.warning('用户名或密码不能为空')
        } else {
            $.ajax({
                type: "post",
                url: "/CounterDrops/weuser/islogin",
                data: {
                    username: logincontroller.username,
                    password: logincontroller.password,
                },
                success: function (data) {
                    if (data.success == true) {
                        toastr.info(data.msg);
                        setTimeout(function () {
                            window.location.href = "/CounterDrops/index/wechat/billnotes";
                        }, 3000);
                    } else {
                        toastr.warning(data.msg);
                    }
                }
            });
        }
    },

    create: function () {
        alert($.cookie('openid'))
        if (logincontroller.cusername == "" || logincontroller.cnickname == "") {
            toastr.warning('用户名或密码不能为空')
        } else if (logincontroller.password1 != logincontroller.password2) {
            toastr.warning('两次密码输入不一致');
        } else {
            $.ajax({
                type: "post",
                url: "/CounterDrops/weuser/createaccount",
                data: {
                    openid: $.cookie('openid'),
                    username: logincontroller.cusername,
                    nickname: logincontroller.cnickname,
                    password: logincontroller.password1,
                },
                success: function (data) {
                    if (data.success == true) {
                        toastr.info(data.msg);
                        setTimeout(function () {
                            window.location.reload();
                        }, 3000);
                    } else {
                        toastr.warning(data.msg);
                    }
                }
            });
        }
    },
});